package com.ruoyi.project.mobile.home;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.utils.R;
import com.ruoyi.common.utils.RFactory;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.banner.service.IBannerService;
import com.ruoyi.project.system.goods.goods.domain.GoodsGoods;
import com.ruoyi.project.system.goods.goods.enums.GoodsStatus;
import com.ruoyi.project.system.goods.goods.service.IGoodsGoodsService;
import com.ruoyi.project.system.goodsclass.domain.GoodsClass;
import com.ruoyi.project.system.goodsclass.enums.ClassIsHome;
import com.ruoyi.project.system.goodsclass.enums.ClassStatus;
import com.ruoyi.project.system.goodsclass.service.IGoodsClassService;
import com.ruoyi.project.system.hotword.service.IHotWordService;
import com.ruoyi.project.system.proclamation.domain.Proclamation;
import com.ruoyi.project.system.proclamation.enums.ProclamationStatus;
import com.ruoyi.project.system.proclamation.service.IProclamationService;
import com.ruoyi.project.system.shopconfig.service.IShopConfigService;

/**
 * 功能：
 *
 * @author：dell
 * @create：2020/6/18 18:19
 * @version：2020 Version：1.0
 * @company：老屋新房 Created with IntelliJ IDEA
 */
@RestController
@RequestMapping("/api/home")
public class HomeController extends BaseController {

	@Autowired
	private IBannerService bannerService;
	@Autowired
	private IGoodsClassService goodsClassService;
	@Autowired
	private IProclamationService proclamationService;
	@Autowired
	private IGoodsGoodsService goodsGoodsService;
	@Autowired
	private IHotWordService hotWordService;
	@Autowired
	private IShopConfigService shopConfigService;

	/**
	 * 查询轮播图
	 * @param uid
	 * @return
	 */
	@GetMapping("/banners")
	private R homeBanners(@RequestParam String uid){
		return RFactory.generateR(this.bannerService.findBannerList());
	}

	/**
	 * 查询分类
	 * @param uid
	 * @return
	 */
	@GetMapping("/class")
	private R homeClass(@RequestParam String uid){
		GoodsClass goodsClass = new GoodsClass();
		goodsClass.setIsHome(ClassIsHome.NORMAL.getValue());
		goodsClass.setStatus(ClassStatus.NORMAL.getValue());
		return RFactory.generateR(this.goodsClassService.selectGoodsClassList(goodsClass));
	}

	/**
	 * 查询公告
	 * @param uid
	 * @return
	 */
	@GetMapping("/proclamations")
	private R homeProclamations(@RequestParam String uid){
		Proclamation proclamation = new Proclamation();
		proclamation.setStatus(ProclamationStatus.SHOW.getValue());
		return RFactory.generateR(this.proclamationService.selectProclamationList(proclamation));
	}


	/**
	 *
	 * @param brand 是否是品牌大牌 0 不是 1 是
	 * @param abroad 是否是境外产品 0 不是 1 是
	 * @param recommend 是否是推荐产品 0 不是 1 是
	 * @param hot 是否是热卖产品 0 不是 1 是
	 * @param spike 是否是秒杀产品 0 不是 1 是
	 * @return
	 */
	@GetMapping("/goods")
	private R homeGoods(@RequestParam String uid,
						@RequestParam(required = false,defaultValue = "") Integer brand,
						@RequestParam(required = false,defaultValue = "") Integer abroad,
						@RequestParam(required = false,defaultValue = "") Integer recommend,
						@RequestParam(required = false,defaultValue = "") Integer hot,
						@RequestParam(required = false,defaultValue = "") Integer spike,
						@RequestParam(required = false,defaultValue = "") String name){
		startPage();
		GoodsGoods goodsGoods = new GoodsGoods();
		goodsGoods.setIsAbroad(abroad);
		goodsGoods.setIsBrand(brand);
		goodsGoods.setIsHot(hot);
		goodsGoods.setIsRecommend(recommend);
		goodsGoods.setHasSpike(spike);
		goodsGoods.setStatus(GoodsStatus.UP_SHELF.getValue());
		goodsGoods.setName(name);
		return RFactory.generateR(getDataTable(this.goodsGoodsService.findGoodsDtoList(goodsGoods)));
	}

	/**
	 * 查询热词
	 * @param uid
	 * @return
	 */
	@GetMapping("/hotwords")
	private R homeHotWord(@RequestParam String uid){
		return RFactory.generateR(this.hotWordService.findAll());
	}

	/**
	 * 查询首页配置信息
	 * @param uid
	 * @return
	 */
	@GetMapping("/config")
	private R homeConfig(@RequestParam String uid){
		return RFactory.generateR(this.shopConfigService.findAll().get(0));
	}

}
